#include <51func.h>
int main(int argc, char *argv[])
{
    // ./1_server 192.168.118.128 1234
    ARGS_CHECK(argc,3);
    // socket
    int sockfd = socket(AF_INET,SOCK_STREAM,0);
    // bind
    struct sockaddr_in serverAddr;
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port = htons(atoi(argv[2]));
    serverAddr.sin_addr.s_addr = inet_addr(argv[1]);
    int ret = bind(sockfd,(struct sockaddr *)&serverAddr,sizeof(serverAddr));
    ERROR_CHECK(ret,-1,"bind");
    // listen
    listen(sockfd,10);
    // accept
    struct sockaddr_in clientAddr;
    socklen_t clientAddrLength = sizeof(clientAddr); //必须赋初值
    int netfd = accept(sockfd,(struct sockaddr *)&clientAddr,&clientAddrLength);
    printf("client ip = %s, port = %d\n",inet_ntoa(clientAddr.sin_addr), ntohs(clientAddr.sin_port));
    sleep(10);
    printf("sleep over!\n");
    ssize_t sret = send(netfd,"niganma",7,0);
    sret = send(netfd,"aiyou",5,0);
    //ssize_t sret = write(netfd,"niganma",7);
    return 0;
}

